package microjavacompiler.egg;
//package att_java;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;

public class TDS<T> extends HashMap<String, T> {

	private static final long serialVersionUID = 1L;

	private TDS<T> parente;

	public TDS() {
		this(null);
	}

	public TDS(TDS<T> p) {
		super();
		parente = p;
	}

	public T chercherLocalement(String n) {
		return get(n);
	}

	public T chercherGlobalement(String n) {
		T i = chercherLocalement(n);
		if (i == null)
			if (parente != null)
				return parente.chercherGlobalement(n);
		return i;
	}

	public void insererTout(TDS<T> tds){
		this.putAll(tds);
	}

	public void inserer(String n, T i) {
		put(n, i);
	}

	public String paramToString() {
		StringBuffer sb = new StringBuffer();
		Set<Entry<String, T>> s = entrySet();
		sb.append("(");
		for (Map.Entry<String, T> e : s){
			sb.append(((ATT_PARAM)e.getValue()).type.getName() + " " + e.getKey()+", ");
		}
		if(s.size()>0){
			sb.delete(sb.length()-2,sb.length() );
		}
		sb.append(")");
		return sb.toString();
	}

	public String toString() {
		StringBuffer sb = new StringBuffer();
		Set<Entry<String, T>> s = entrySet();
		for (Map.Entry<String, T> e : s){
			sb.append(e.getKey() + " -> " + e.getValue() + '\n');
		}
		return sb.toString();
	}
}
